#ifndef REQUEST_H
#define REQUEST_H

#include "database.h"

enum {
	ANNOUNCE,
	LOOK,
	GETFILE,
	UPDATE	
};

struct criterion {
	char * entity;
	char comp;
	char * value;
	
	struct criterion * next;
};


int request_type (char *req);

//look part
struct criterion ** new_criterion_tab ();
struct criterion * new_criterion ();
int size_tab (struct criterion ** tab);
void free_criterion_list (struct criterion ** ls);

struct criterion * parse_criterion (struct criterion * c, char * elt);					
struct criterion ** add_criterion (struct criterion ** ls, struct criterion * c);					

char * look_with_criterions (char * rep, struct criterion ** ls);
char * check_files_of_peer_look (struct peer *p, struct criterion ** ls, char * rep);
int check_criterion_file (struct criterion ** ls, struct file * f);

//getfile part
char * find_peers_getfile (char * key, char * rep);
char * check_peer_key (struct peer * p, char * key, char * rep);

//update part
void update_seed (struct peer * p_current, struct peer * p_new, char * key);
void update_leech (struct peer * p_new, char * key);
int is_leech (struct peer * p, char * key);
int is_seed (struct peer * p, char * key);
void replace_peers (struct peer * p_old, struct peer * p_new);

//string functions
int equal (char *str1, char *str2);

char first_char (char *str);
char last_char (char *str);

char *remove_first_char (char *str);
char *remove_last_char (char *str);

char **split (char *str);

#endif
